package com.zhz.lib.project.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zhz.lib.project.domain.hotlink.Hotlink;
import com.zhz.lib.project.service.custom.CustomService;
import com.zhz.lib.project.service.hotlink.HotlinkService;
import com.zhz.lib.project.service.news.NewsService;
import com.zhz.lib.project.vo.custom.CustomVO;
import com.zhz.lib.project.vo.news.NewsVO;

@Controller
@RequestMapping("/index.htm")
public final class IndexController {
    private static Logger  logger      = Logger.getLogger(IndexController.class);
    private static int     firstResult = 0;
    private static int     maxResults  = 8;
    @Autowired
    private NewsService    newsService;
    @Autowired
    private HotlinkService hotlinkService;
    @Autowired
    private CustomService  customService;

    @SuppressWarnings("unchecked")
    @RequestMapping(method = RequestMethod.GET)
    public String get(ModelMap model, HttpServletRequest request, HttpServletResponse response) {
        // CALIS相关链接
        List<Hotlink> xiangguanlianjielink = hotlinkService.getHotLink("xiangguanlianjielink");
        model.put("xiangguanlianjielink", xiangguanlianjielink);
        // 成员馆
        List<Hotlink> chengyuanguanlink = hotlinkService.getHotLink("chengyuanguanlink");
        model.put("chengyuanguanlink", chengyuanguanlink);
        // 服务推介
        List<Hotlink> fuwutuijielink = hotlinkService.getHotLink("fuwutuijielink");
        model.put("fuwutuijielink", fuwutuijielink);
        // 共享资源
        List<Hotlink> gongxiangziyuanlink = hotlinkService.getHotLink("gongxiangziyuanlink");
        model.put("gongxiangziyuanlink", gongxiangziyuanlink);

        // 获取最新消息
        List<NewsVO> newsVOList = newsService.getLatestNews(firstResult, maxResults);
        model.put("newsVOList", newsVOList);

        // 获取顶级模块
        List<CustomVO> customVOList = customService.getTopCustom();
        model.put("customVOList", customVOList);

        // 获取采购信息
        List<CustomVO> caigouxinxiCustomVOList = customService.getSubCustom("3");
        model.put("caigouxinxiCustomVOList", caigouxinxiCustomVOList);
        // 获取培训信息
        List<CustomVO> peixunxinxiCustomVOList = customService.getSubCustom("5");
        model.put("peixunxinxiCustomVOList", peixunxinxiCustomVOList);
        // 获取会议信息
        List<CustomVO> huiyixinxiCustomVOList = customService.getSubCustom("4");
        model.put("huiyixinxiCustomVOList", huiyixinxiCustomVOList);
        // 获取文件下载
        List<CustomVO> wenjianxiazaiCustomVOList = customService.getSubCustom("6");
        model.put("wenjianxiazaiCustomVOList", wenjianxiazaiCustomVOList);

        return "index";
    }

    @RequestMapping(method = RequestMethod.GET, params = "event=thanks")
    public String thanks(ModelMap model, HttpServletRequest request, HttpServletResponse response) {
        return "thanks";
    }
}
